﻿using POC.Azure.Model;
using POC.Azure.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using wlog.Model;

namespace wlog.Shell.Storage.Queue
{
    public class QueueGetCommand : QueueStorageCommand
    {
        string queueName;
        string[] columns;
        bool _toDelete = false;
        public QueueGetCommand(bool iSPeek)
        {
            _toDelete = iSPeek;
        }
        public override void Setup(string[] args)
        {
            base.Setup(args);
            queueName = this.objectName;
            base.CreateTask(() => { SelectCommand(); });
        }
        public OutputChannel SelectCommand()
        {
            try
            {
                var repo = new QueueStorageRespository<LogEntry>(GetSetUpAccount(), queueName, MessageFormat.Xml);
                byte[] message = repo.GetMessage(_toDelete);
                if (message == null) Results.Add("No messages found.");
                Results.Add("Message=>[[\n" + UTF8Encoding.UTF8.GetString(message));
                Results.Add("\n]]");
            }
            catch (Exception azureEx)
            {
                Results.WriteLine("Error ccreating table {0} ", azureEx.Message);

            }
            return Results;
        }

    }
}
